package com.example.erp.controller;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.erp.entity.Book;
import com.example.erp.service.BookService;

import jakarta.annotation.Resource;

/**
 * 常规测试。
 */
@RestController
@RequestMapping("/api/books")
public class BookController {

	@Resource
	private BookService bookService;

	@GetMapping("/search/title")
	public ResponseEntity<List<Book>> searchBooksByTitle(@RequestParam String title) {
		List<Book> books = bookService.findBooksByTitle(title);
		return ResponseEntity.ok(books);
	}

	@GetMapping("/search/author")
	public ResponseEntity<List<Book>> searchBooksByAuthor(@RequestParam String author) {
		List<Book> books = bookService.findBooksByAuthor(author);
		return ResponseEntity.ok(books);
	}

	@GetMapping("/search/category")
	public ResponseEntity<List<Book>> searchBooksByCategory(@RequestParam String category) {
		List<Book> books = bookService.findBooksByCategory(category);
		return ResponseEntity.ok(books);
	}
}
